package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.MarketAdmin;
import com.cskaoyan.bean.lihaoming.AdminPasswordBO;
import com.cskaoyan.bean.lihaoming.BaseRespVo3;
import com.cskaoyan.mapper.AdminMapper;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lihaoming
 * @Description
 * @Create 2022-06-30 10:22
 * @Version
 */
@RestController
public class AdminPasswordController {
    @Autowired
    AdminMapper adminMapper;
    @RequestMapping("admin/profile/password")
    public BaseRespVo ChangePassWord(@RequestBody AdminPasswordBO adminPasswordBO){
        Subject subject = SecurityUtils.getSubject();
        MarketAdmin marketAdmin = (MarketAdmin) subject.getPrincipals().getPrimaryPrincipal();
        String password=adminMapper.selectPassWordById(marketAdmin.getId());
        if(!adminPasswordBO.getOldPassword().equals(password)){
            return BaseRespVo.error2();
        }
        adminMapper.changePassword(marketAdmin.getId(),adminPasswordBO.getNewPassword());
        return BaseRespVo.ok();
    }
}
